﻿using System;
using System.Collections.Generic;
using System.Text;

namespace testca
{
    class MemoryAllocator
    {
        static ulong heap_start = 0;
        static ulong heap_end = 0;
        static ulong cur_end_of_heap = 0;

        public static void DefineHeap(ulong start, ulong end)
        {
            heap_start = start;
            heap_end = end;
            cur_end_of_heap = heap_start;
        }

        [ABI.MethodAlias("gcmalloc")]
        [ABI.AlwaysCompile]
        public static ulong Alloc(ulong size)
        {
            if (size > (heap_end - cur_end_of_heap))
                return 0;
            cur_end_of_heap += size;
            return cur_end_of_heap - size;
        }
    }
}
